package com.donn.securitycontrolplatform.role.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.donn.securitycontrolplatform.common.Result;
import com.donn.securitycontrolplatform.role.entity.TRole;
import com.donn.securitycontrolplatform.role.service.ITRoleService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;


/**
 * <p>
 * 角色信息表 前端控制器
 * </p>
 *
 * @author zhenglixiang
 * @since 2022-06-10
 */
@RestController
@RequestMapping("/scp/api/role")
@Tag(name = "role-controller", description = "角色接口")
public class TRoleController {
    @Autowired
    ITRoleService roleService;

    @ApiOperation(value = "新增角色")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "roleName", value = "角色名"),
            @ApiImplicitParam(name = "iconType", value = "图标编码（默认）"),
            @ApiImplicitParam(name = "iconUrl", value = "图标链接"),
            @ApiImplicitParam(name = "createBy", value = "创建人")
    })
    @PostMapping("/add")
    @ResponseBody
    public Result add(@ApiParam @RequestBody TRole role) {

        return roleService.insertRole(role);
    }

    @ApiOperation(value = "修改角色信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "roleName", value = "角色名"),
            @ApiImplicitParam(name = "iconType", value = "图标编码（默认）"),
            @ApiImplicitParam(name = "iconUrl", value = "图标链接"),
            @ApiImplicitParam(name = "createBy", value = "创建人"),
            @ApiImplicitParam(name = "updateBy", value = "修改人")
    })
    @PutMapping("/update")
    @ResponseBody
    public Result update(@RequestBody TRole role) {
        return roleService.updateRole(role);
    }

    @ApiOperation(value = "删除角色信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "roleId", value = "角色id")
    })
    @DeleteMapping("/delete")
    @ResponseBody
    public Result delete(@RequestParam String roleId) {
        return roleService.deleteRole(roleId);
    }

    @ApiOperation(value = "查询列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "roleName", value = "角色名"),
            @ApiImplicitParam(name = "createBy", value = "创建人"),
            @ApiImplicitParam(name = "status", value = "启用状态"),
            @ApiImplicitParam(name = "current", value = "当前页"),
            @ApiImplicitParam(name = "size", value = "条数")
    })
    @GetMapping("/list")
    @ResponseBody
    public Result list(@ApiIgnore TRole role, Page page) {
        return roleService.selectRoleList(role, page);
    }

    @ApiOperation(value = "角色详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "roleId", value = "角色Id")
    })
    @GetMapping("/get")
    @ResponseBody
    public Result get(@RequestParam String roleId) {
        return roleService.getRoleById(roleId);
    }
}
